package cn.tedu.wallet.controller;

import cn.tedu.base.response.JsonResult;
import cn.tedu.base.response.StatusCode;
import cn.tedu.wallet.pojo.param.RechargeParam;
import cn.tedu.wallet.service.WalletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.text.DecimalFormat;

@RestController
@RequestMapping("/wallet")
@Slf4j
@Api(tags = "支付模块")
public class WalletController {
    @Autowired
    private WalletService walletService;

    @PostMapping("/recharge")
    @ApiOperation("充值接口")
    public JsonResult recharge(@RequestBody RechargeParam param) {
        log.debug("充值数据：{}",param);
        walletService.doRecharge(param);
        log.debug("充值成功！");
        return new JsonResult(StatusCode.OPERATION_SUCCESS);
    }

    @GetMapping("/detail/{userId}")
    @ApiOperation("获取钱包余额")
    public JsonResult getWalletDetail(@PathVariable Long userId) {
        log.debug("控制器获取用户{}的余额",userId);
        String balance = walletService.getBalance(userId);
        log.debug("控制器返回用户{}的余额为：{}",userId,balance);
        //返回值应当是小数点后两位
        return new JsonResult(StatusCode.OPERATION_SUCCESS,balance);
    }
}
